package main

import (
	"bufio"
	"bytes"
	"fmt"
	"github.com/go-vgo/robotgo"
	"io"
	"io/ioutil"
	"log"
	"time"
)

func main() {
	addKeysListen(printMaren, `q`)
	time.Sleep(10 * time.Hour)
}

func printMaren() {
	data, err := ioutil.ReadFile("w.txt")
	if err != nil {
		log.Println(err)
		return
	}
	buf := bufio.NewReader(bytes.NewBuffer(data))
	for {
		x, _, err := buf.ReadLine()
		if err != nil {
			if err == io.EOF {
				break
			}
			log.Println(err)
			return
		}
		robotgo.KeyTap("enter")
		robotgo.TypeStr(string(x))
		robotgo.KeyTap("enter")
		time.Sleep(300 * time.Millisecond)
	}
}

func addKeysListen(f func(), key string, arr ...string) {
	go func() {
		for {
			if ok := robotgo.AddEvents(key, arr...); ok {
				fmt.Println(111)
				f()
			}
		}
	}()
}
